package com.guigu.basedservice.controller;


import com.github.pagehelper.PageInfo;
import com.guigu.basedservice.dto.BaseCarPartsSkuDto;
import com.guigu.basedservice.dto.ProductDto;
import com.guigu.basedservice.entity.BaseCarBrand;
import com.guigu.basedservice.entity.BaseCarPartsSku;
import com.guigu.basedservice.entity.BasePartsType;
import com.guigu.basedservice.service.BaseCarPartsSkuDtoService;
import com.guigu.basedservice.service.BaseCarPartsSkuService;
import com.guigu.basedservice.service.BasePartsTypeService;
import com.guigu.basedservice.service.ProductDtoService;
import com.guigu.basedservice.vo.BasePartsTypeVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 配件产品库(含品牌规格型号)(sku级) 前端控制器
 * </p>
 *
 * @author Heyuhang
 * @since 2024-10-08
 */
@CrossOrigin
@RestController
@RequestMapping("/basedservice/base-car-parts-sku")
public class BaseCarPartsSkuController {

    @Resource
    private ProductDtoService productDtoService;

    @Autowired
    private BasePartsTypeService basePartsTypeService;

    @Autowired
    private BaseCarPartsSkuService baseCarPartsSkuService;

    @ApiOperation("查询所有BaseCarPartsSku(配件产品库(含品牌规格型号)(sku级))分页数据")
    @RequestMapping("/getBaseCarPartsSku/{currentPage}/{pageSize}")
    public PageInfo<ProductDto> getBaseCarPartsSku(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody BasePartsTypeVo vo
    ){
        System.out.println("BasePartsTypeVo++++"+vo);
        PageInfo<ProductDto> baseCarPartsSkuPageInfo = productDtoService.getBaseCarPartsSku(currentPage,pageSize,vo);
        System.out.println("baseCarPartsSkuPageInfo++++"+baseCarPartsSkuPageInfo);
        return baseCarPartsSkuPageInfo;
    }

    @RequestMapping("/getOne/{id}")
    public ProductDto getOne(@PathVariable("id") String id){
        return productDtoService.getOne(id);
    }

    @RequestMapping("/listProductDto")
    public List<ProductDto> listProductDto(){
        return productDtoService.listProductDto();
    }

    @RequestMapping("/updateProductDto")
    public Boolean updateProductDto(@RequestBody ProductDto productDto){
        System.out.println("productDto++++"+productDto);
        BasePartsType basePartsType = new BasePartsType();
        basePartsType.setName(productDto.getName());
        basePartsType.setCode(productDto.getCode());
        BaseCarPartsSku baseCarPartsSku = new BaseCarPartsSku();
        baseCarPartsSku.setBrand(productDto.getBrand());
        baseCarPartsSkuService.updateById(baseCarPartsSku);
        basePartsTypeService.updateById(basePartsType);
        return true;
    }


}

